package com.yingxue.lesson.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebAppConfig implements WebMvcConfigurer {

    @Value("${file.static-path}")
    private String filStaticPath;
    @Value("${file.path}")
    private String filePath;

    /**
     * 文件路径映射
     */
    //上传的文件在当前项目实际目录file文件夹下，访问路径如：http://localhost:8080/upload/image/test.jpg
    // 其中upload表示访问的前缀。"file:H:/Business/image/"是文件真实的存储路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(filStaticPath).addResourceLocations("file:"+filePath);
    }
}
